import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        zc9993: props.values.zc9993,
        a3201: props.values.a3201,
        a3204: props.values.a3204,
        a3207: props.values.a3207,
        a3211: props.values.a3211,
        a3212: props.values.a3212,
        a3214: props.values.a3214,
        a3217: props.values.a3217,
        a3221: props.values.a3221,
        a3224: props.values.a3224,
        a3200: props.values.a3200

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			} */

			if(formVals.a3201) {
      			formVals.a3201 = moment(formVals.a3201._d).format("YYYY-MM-DD");
      		}
			if(formVals.a3204) {
      			formVals.a3204 = moment(formVals.a3204._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file;
			handleSubmitSubsetInfo(formVals,"update_for_staff_curriculumInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="所在单位">
			              {getFieldDecorator('a3207', {
			              rules: [{ required: true, message: '请输入1-10个字符',max: 10}],
			              initialValue: formVals.a3207,
			              })(<Input placeholder="1-10个字符"/>)}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="起始日期">
                    {getFieldDecorator('a3201', {
                      rules: [{ required: true, message: '请选择'}],
                      initialValue: formVals.a3201?moment(formVals.a3201):null,
                          })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
                      </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="截止日期">
			              {getFieldDecorator('a3204',{
			              	initialValue: formVals.a3204?moment(formVals.a3204):null,
			              	    })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
			              	</FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="身份或职务说明">
			              {getFieldDecorator('a3214', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a3214,
			              })(<Input placeholder="1-10个字符"/>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="履历类别">
			              {getFieldDecorator('a3221', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a3221,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              	  	{dicListByPcode('YT') != undefined?dicListByPcode('YT').map((item,index) => {
			              	  		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              	  	}):null}
			              	  </Select>
			              )}
			          </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="基层工作的标志">
			              {getFieldDecorator('a3212',{
			                rules: [{ required: false, message: '请选择！'}],
                      initialValue: formVals.a3212,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('R1') != undefined?dicListByPcode('R1').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
			              )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="履历说明">
			              {getFieldDecorator('a3224', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a3224,
			              })(
                      <Input placeholder="1-40个字符" />
                    )}
			          </FormItem>
			        </Col>


			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          	<Col md={12} sm={24}>
                  <Button
                  	size="large"
                  	style={{marginRight: '10px'}}
                  	onClick={()=> {
                  		const { form } = this.props;
          				form.resetFields();
                  		cancelEditJobInfo(spinIndex);
                  	}}>
                  	取消
                 	</Button>
                  <Button size="large" type="primary" htmlType="submit">保存</Button>
              </Col>
          </Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="所在单位">
			              {getFieldDecorator('a3207')(<span>{formVals.a3207}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="起始日期">
			              {getFieldDecorator('zc9993')(<span>{formVals.zc9993?moment(formVals.zc9993).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="截止日期">
			              {getFieldDecorator('a3204')(<span>{formVals.a3204?moment(formVals.a3204).format('YYYY-MM-DD'):null}</span>)}
			              </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="身份或职务说明">
			              {getFieldDecorator('a3214')(<span>{formVals.a3214}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="履历类别">
			              {getFieldDecorator('a3221')(<span>{formVals.a3221}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="基层工作的标志">
			              {getFieldDecorator('a3212')(<span>{formVals.a3212}
			              	</span>)}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="履历说明">
			              {getFieldDecorator('a3224')(<span>{formVals.a3224}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
